﻿
@{
    ViewBag.Title = "记账项目";
    Layout = "~/Views/Shared/_Form.cshtml";
}
<style>
    i {
        font-style: normal;
    }
</style>
<script>
    var editData = localStorage.getItem("editData");
    var editDataJson = JSON.parse(editData);
    var dj;
    var dw;
    $(function () {
        if (!!editDataJson) {
            $("#form1").formSerialize(editDataJson);
        }
        init();
        AddHtmlTDXM(); //增加空的行替代项目
        //根据数量和单价算出总价
        $("#tblTDXM").on('input', '.txt-num', function () {
            var idx = $(this).index();
            var dj = $("#tdxmdj" + idx).val();
            var zje = dj * $(this).val();
            $("#zje" + idx).html(zje);


        });
    });

    function init() {
        //治疗项目选择浮层绑定
        $('#zlxmName, #tdxmName').newtouchBatchFloatingSelector({
            width: 600,
            height: 280,
            caption: "选择项目",
            url: '/SystemManage/SysChargeItem/GetChargeItemSelectData',
            ajaxparameters: function ($thisinput) {
                return "zlfzlbz=true&mzzybz=2&keyword=" + $thisinput.val();
            },
            minlength: 2,
            itemdbclickhandler: function ($thistr, $thisinput) {
                if ($thisinput.attr('id') === 'zlxmName') {
                    $('#zlxmName').val($thistr.attr('data-sfxmmc'));
                    $('#zlxmCode').val($thistr.attr('data-sfxmCode'));
                    $('#sfdlCode').val($thistr.attr('data-sfdlCode'));
                    $('#sfdlmc').val($thistr.attr('data-sfdlmc'));
                    dj = $thistr.attr('data-dj');
                    dw = $thistr.attr('data-dw');
                    $("#sfxmdj").val("dj");
                    $("#sfbz").val(dj + '/' + dw);
                    if ($thistr.attr('data-duration') !== "null") {
                        $('#zlsc').val($thistr.attr('data-duration'));
                    }
                    $('#sl').val('1');
                }
                else if ($thisinput.attr('id') === 'tdxmName') {
                    $('#tdxmName').val($thistr.attr('data-sfxmmc'));
                    $('#tdxmCode').val($thistr.attr('data-sfxmCode'));
                    dj = $thistr.attr('data-dj');
                    dw = $thistr.attr('data-dw');
                    $("#tdxmsfbz").val(dj + '/' + dw);
                    $('#tdxmSl').val('1');
                }
            },
            colModel: [
                { label: '代码', name: 'sfxmCode', widthratio: 10 },
                { label: '名称', name: 'sfxmmc', widthratio: 15 },
                { label: '拼音', name: 'py', widthratio: 10 },
                { label: '收费大类', name: 'sfdlCode', widthratio: 10, hidden: true },
                { label: '收费大类', name: 'sfdlmc', widthratio: 10 },
                { label: '单位', name: 'dw', widthratio: 10 },
                { label: '单价', name: 'dj', widthratio: 10 },
                { label: '时长', name: 'duration', widthratio: 10 }
            ]
        });
    }

    //增加空的行替代项目
    function AddHtmlTDXM() {
        $("#addIcon").click(function () {
            //增加替代项目
            var tdxmHeight = parseInt($("#divTDXM").height());
            var trlen = parseInt($("#tblTDXM tr").length) + 1;
            if (tdxmHeight < 288) {
                $("#divTDXM").height(tdxmHeight + parseInt(36));
                var html = '<tr>';
                html += '<th class="formTitle">替代项目：</th>';
                html += '<td class="formValue">';
                html +=
                    '<input type="text" class="form-control" id="tdxmName' + trlen + '" name="tdxmName' + trlen + '" />';
                html += '<input id="tdxmCode' + trlen + '" type="text" style="display:none;" class="form-control" />';
                html += '<input id="tdxmDw' + trlen + '" type="text" style="display:none;" class="form-control" />';
                html += '</td>';
                //html += '";
                html += '<th class="formTitle">数量：</th>';
                html +=
                    '<td class="formValue">' +
                    '<input type="text" id="tdxmSl' + trlen + '" name="tdxmSl' + trlen + '" value="1" class="form-control txt-num" >' +
                    '<input type="text" id="tdxmdj' + trlen + '" id="tdxmdj' + trlen + '" class="form-control" style="display:none"></td>';
                html += '<th class="formTitle">收费标准：</th>';
                html += '<td class="formValue"><input type="text" class="form-control newtouch_Readonly" id="tdxmsfbz' +
                    trlen +
                    '" ' +
                    '</td>';
                html +=
                    '<td class="formTitle"><i class="fa fa-minus-square-o" aria-hidden=true style="font-size: 20px;color:#00a0e9; position: absolute; right: 55px; top: 7px" onclick="DelCurrentRow(this)"></i></td>';
                html += '<th class="formValue">';
                html += '<th class="formTitle">金额：</th>';
                html += '<td class="formValue"><span style="font-size: 13px">￥<i id="zje' +
                    trlen +
                    '" >0.00</i></span></td>';
                html += '</tr>';
                $("#tblTDXM tbody").prepend(html);
                $("#tblTDXM").height(parseInt(tdxmHeight) + parseInt(36));
            }
        });
    }

    //删除当前行
    function DelCurrentRow(obj) {
        var tdxmHeight = $("#divTDXM").height();
        $(obj).parent().parent().remove();
        $("#divTDXM,#tblTDXM").height(parseInt(tdxmHeight) - parseInt(36));
    }

    //关闭子页面，保存项目信息到父页面Grid
    function SubmitForm() {
        var data = [];
        data[0] = $("#form1").formSerialize();
        data[0].bxje = $("#bxje").html(); //报销金额
        data[0].dj = dj; //单价
        data[0].dw = dw; //单价
        if (data[0].isSaved === undefined) {
            data[0].isSaved = 1;
        }
        if (!!editDataJson) { //如果是修改当前未保存的数据，先删除，再重新添加
            $.currentWindow().GlobalData.splice(editDataJson.id - 1, 1);
        }
        $.currentWindow().ReloadGridData(data);
        $.loading(false);
        $.modalClose();
    }

</script>
<div class="panel panel-default" style="margin-top:10px;" id="form1">
    <input type="hidden" id="py" name="py" />
    <table class="form">
        <tr>
            <th class="formTitle  ">治疗师一：</th>
            <td class="formValue"><input type="text" class="form-control" id="zlsgh1" /></td>
            <th class="formTitle  ">治疗师二：</th>
            <td class="formValue"><input type="text" class="form-control" id="zlsgh2" /></td>
            <th class="formTitle  ">治疗师三：</th>
            <td class="formValue"><input type="text" class="form-control" id="zlsgh3" /></td>
            <th class="formTitle  ">记账时间：</th>
            <td class="formValue"><input type="text" class="form-control input-wdatepicker" id="jzsj" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd HH:mm:ss' })" style="width: 180%" /></td>
        </tr>
        <tr>
            <th class="formTitle  ">治疗项目：</th>
            <td class="formValue">
                <input id="zlxmName" type="text" class="form-control" />
                <input id="zlxmCode" type="text" style="display:none;" class="form-control" />
                <input id="sfdlCode" type="text" style="display:none;" class="form-control" />
                <input id="sfdlmc" type="text" style="display:none;" class="form-control" />
                <input id="sfxmdj" type="text" style="display:none;" class="form-control" />
            </td>
            <th class="formTitle  ">数量：</th>
            <td class="formValue"><input type="text" class="form-control" id="sl" name="sl" value="1" /></td>
            <th class="formTitle  ">收费标准：</th>
            <td class="formValue"><input type="text" class="form-control newtouch_Readonly" id="sfbz" /></td>
            <th class="formTitle  ">治疗时长：</th>
            <td class="formValue"><input type="text" class="form-control " id="zlsc" placeholder="分钟" /></td>
            <th class="formTitle  ">金额：</th>
            <td class="formValue">
                <span style="font-size: 13px" id="je">￥0.00</span>
                <i class="fa fa-plus-square-o" aria-hidden="true" style="font-size: 20px; color: rgb(0, 160, 233);margin-left: 20px;" id="addIcon"></i>
            </td>
        </tr>
    </table>
    <div style="padding: 2px 0; border-top: 1px dashed rgb(221, 221, 221); position: relative" id="divTDXM">
        <table class="form" id="tblTDXM">
            <tr>
                <th class="formTitle">替代项目：</th>
                <td class="formValue">
                    <input id="tdxmName1" type="text" class="form-control" value="" />
                    <input id="tdxmCode1" type="text" style="display:none;" class="form-control" />
                    <input id="tdxmDw1" type="text" style="display:none;" class="form-control" />
                    <input id="tdxmdj1" type="text" style="display:none;" class="form-control" />
                </td>
                <th class="formTitle  ">数量：</th>
                <td class="formValue"><input type="text" class="form-control txt-num" id="tdxmSl1" name="tdxmSl1" value="1" /></td>
                <th class="formTitle  ">收费标准：</th>
                <td class="formValue"><input type="text" class="form-control newtouch_Readonly" id="tdxmsfbz1" name="tdxmsfbz1" /></td>
                <td class="formTitle"><i class="fa fa-minus-square-o" aria-hidden=true style="font-size: 20px; color: #00a0e9; position: absolute; right: 55px; top: 7px" onclick="DelCurrentRow(this)"></i></td>
                <th class="formValue">
                <th class="formTitle">金额：</th>
                <td class="formValue"><span style="font-size: 13px">￥<i id="zje1">0.00</i></span></td>
            </tr>
        </table>
    </div>
    <div style="float: right; position: relative; padding-top: 5px; padding-right: 40px;">
        <span style="font-size: 20px">总金额：</span>
        <span style="color: red; font-size: 25px;">￥<i id="bxje">0.00</i></span>
    </div>
</div>

